import { _decorator, Component, AudioClip, game, AudioSource, director } from "cc";

const { ccclass, property } = _decorator;

@ccclass
export default class SoundManager extends Component {
    private static instance: SoundManager;
    static get Instance() {
        return this.instance;
    }

    @property(AudioClip)
    buttonSound: AudioClip;

    @property(AudioClip)
    winSound: AudioClip;

    @property(AudioClip)
    failSound: AudioClip;

    @property(AudioSource)
    audioSource: AudioSource;

    // LIFE-CYCLE CALLBACKS:

    onLoad() {
        SoundManager.instance = this;
        director.addPersistRootNode(SoundManager.Instance.node);
    }

    start() {
    }

    // update (dt) {}

    PlayButton() {
        this.audioSource.playOneShot(this.buttonSound, 1);
    }

    PlayWin() {
        this.audioSource.playOneShot(this.winSound, 1);
    }

    PlayFail() {
        this.audioSource.playOneShot(this.failSound, 1);
    }
}
